#include "MainFrame/StatusBar/StatusBar.h"
#include <QEvent>

StatusBar::StatusBar(QWidget *parent) :
    QStatusBar(parent),
    m_pStatusBarLabel(nullptr),
    m_pCursorPosLabel(nullptr)
{
    initStatusBar();
}

StatusBar::~StatusBar()
{

}

void StatusBar::initStatusBar()
{
    m_pStatusBarLabel = new QLabel("Welcome to Rivia Image Manipulation Platform!");
    m_pStatusBarLabel->setAlignment(Qt::AlignRight);
    this->addPermanentWidget(m_pStatusBarLabel);

    m_pCursorPosLabel = new QLabel("CursorPos:");
    m_pCursorPosLabel->setAlignment(Qt::AlignLeft);
    this->addWidget(m_pCursorPosLabel);
}

void StatusBar::changeEvent(QEvent *event)
{
    QWidget::changeEvent(event);
    switch (event->type())
    {
    case QEvent::LanguageChange:
        initTrans();
        break;
    default:
        break;
    }
}

void StatusBar::initTrans()
{
    m_pStatusBarLabel->setText(tr("Welcome to Rivia Image Manipulation Platform!"));
    m_pCursorPosLabel->setText(tr("CursorPos:"));
}

void StatusBar::onCursorPosChanged(QPoint &cursorpos)
{
    m_pCursorPosLabel->setText(tr("CursorPos: ") + "X " + QString::number(cursorpos.x())
                               + ", Y " + QString::number(cursorpos.y()));
}
